#include "hal_usart.h"

typedef struct{
	uint32_t DMAx;
	dma_channel_enum Channle;
	uint32_t USARTx;
}DMA_Channel_TypeDef;

static DMA_Channel_TypeDef  UARTTxDMAChannleTable[MAX_UART_CNT]=
															{
															   {DMA0,   DMA_CH1,    USART_COCK},
															   {DMA0,   DMA_CH6,    USART_CAT1},
																 {DMA1,   DMA_CH4,    USART_DEBUG},
											
															};
void HAL_UART_Receive_DMA(UARTPortDef port, uint8_t *tbuff, uint16_t tlen)
{
	UARTRxTimeOutTab[port].buff = tbuff;
	UARTRxTimeOutTab[port].maxLen = tlen;
	UARTRxTimeOutTab[port].len = 0;
	UARTRxTimeOutTab[port].rxEnd = 0;
	UARTRxTimeOutTab[port].timeOut = 0;
	UARTRxTimeOutTab[port].flag = 0;
}

void HAL_UART_Transmit_DMA(UARTPortDef port, uint8_t *tbuff, uint16_t tlen)
{
		dma_channel_disable(UARTTxDMAChannleTable[port].DMAx,UARTTxDMAChannleTable[port].Channle);
	
		usart_dma_transmit_config(UARTTxDMAChannleTable[port].USARTx, USART_DENT_DISABLE);
	
    /* configure memory base address */
    DMA_CHMADDR(UARTTxDMAChannleTable[port].DMAx, UARTTxDMAChannleTable[port].Channle) = (uint32_t)tbuff;          //传地址
    /* configure the number of remaining data to be transferred */
    DMA_CHCNT(UARTTxDMAChannleTable[port].DMAx, UARTTxDMAChannleTable[port].Channle) = tlen;
	
//	DMA_Cmd(UARTTxDMAChannleTable[port], ENABLE);
	
		dma_channel_enable(UARTTxDMAChannleTable[port].DMAx, UARTTxDMAChannleTable[port].Channle);
	
		usart_dma_transmit_config(UARTTxDMAChannleTable[port].USARTx, USART_DENT_ENABLE);
}


